﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Sublimation
{
    public class Trash : GameComponent
    {
        protected WorldProperties worldProperties;
        protected List<EnemyUnit> removableEnemies;
        public List<EnemyUnit> RemovableEnemies
        {
            get { return this.removableEnemies; }
        }

        protected List<Tower> removableTowers;
        public List<Tower> RemovableTowers
        {
            get { return this.removableTowers; }
        }
        public Trash(WorldProperties worldproperties):base(worldproperties.Game)
        {
            this.worldProperties = worldproperties;
            worldproperties.Game.Components.Add(this);
            UpdateOrder = 100;
            removableEnemies = new List<EnemyUnit>();
            removableTowers = new List<Tower>();
        }


        //do all the removals at the end in one time to avoid concurent acces in 
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            foreach (EnemyUnit unit in RemovableEnemies)
            {
                worldProperties.Enemies.Remove(unit);
            }
            foreach (Tower tower in RemovableTowers)
            {
                worldProperties.Players[0].Towers.Remove(tower);
            }
            removableEnemies = new List<EnemyUnit>();
            removableTowers = new List<Tower>();
        }
    }
}
